//
//  UIBarButtonItem+Extetion.swift
//  VIZ微博
//
//  Created by 位立志 on 16/4/8.
//  Copyright © 2016年 位立志. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    convenience init(imageName:String?=nil, title:String?=nil, target:AnyObject?, action:Selector) {
        
        self.init()
        
        let btn = UIButton()
        //添加点击事件
        btn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        //设置图片
        if let img = imageName{
            btn.setImage(UIImage(named: img), forState: .Normal)
            btn.setImage(UIImage(named: img + "_highlighted"), forState: .Highlighted)
        }
        
        
        //设置文字大小
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        
        //设置文字颜色
        btn.setTitleColor(UIColor.blackColor(), forState: .Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        btn.setTitle(title, forState: .Normal)
        
        
        //必须设置大小
        btn.sizeToFit()
        //必须要设置在customView上
        customView = btn
    }
    
}















